package creator.single;

/**
 * 单例: 饿汉式
 * 组合
 * 静态块
 * 类加载过程中初始化
 * 线程安全
 */
public class HungerySingle {

    private HungerySingle() {

    }

    private final static HungerySingle instance = new HungerySingle();

    public static HungerySingle getInstance() {
        return instance;
    }

}

class HungerSingle2 {
    private HungerSingle2() {

    }

    private static HungerSingle2 instance;

    static {
        instance = new HungerSingle2();
    }

    public static HungerSingle2 getInstance() {
        return instance;
    }
}

class Test1 {
    public static void main(String[] args) {
        HungerySingle instance = HungerySingle.getInstance();
        HungerySingle instance2 = HungerySingle.getInstance();
        System.out.println(instance == instance2);
    }
}
